/*
 * This source code is part of TWaver 4.0
 *
 * Serva Software PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 * Copyright 2002 - 2011 Serva Software. All rights reserved.
 */

package demo.table.person;

import java.awt.Graphics;

import javax.swing.event.ChangeEvent;

import twaver.TDataBox;
import twaver.table.PropertySheetEvent;
import twaver.table.PropertySheetListener;
import twaver.table.TPropertySheet;

public class PersonSheet extends TPropertySheet{
	
	private boolean lazyMode = false;
	private boolean invalidateRows = false;
	
	public PersonSheet(TDataBox box){
		super(box);
		this.setEditable(true);
		this.addPropertySheetListener(new PropertySheetListener(){
			public void propertySheetChanged(PropertySheetEvent event) {
				int type = event.getType();
				if(type == PropertySheetEvent.MODEL_PUBLISHED ||
						type == PropertySheetEvent.VALUE_CHANGED){
					invalidateRows();
				}
			}
		});
	}
	
	private void invalidateRows(){
		if(lazyMode){
			invalidateRows = true;	
		}else{
			this.packAllRows();
		}
	}
	
	public void columnMarginChanged(ChangeEvent e) {
		super.columnMarginChanged(e);
		invalidateRows();	
	}
	
    public void paintComponent(Graphics g) {
        if(invalidateRows){
        	packAllRows();
        	invalidateRows = false;
        }
        super.paintComponent(g);
    }
}